import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Vector;


public class ProcessedDb implements java.io.Serializable
{
	private static final long serialVersionUID = 1L;
	public float[][] m_TfIdfMatrix;
	public int[] m_classes_list;
	public int[] m_doc_ids_list;
	//
	ArrayList<HashMap<Integer, Float>> m_tfIdfList;
	
	HashMap<Integer, Integer> m_termid_to_frquenecy = new HashMap<Integer, Integer>();
	Map<String, Integer> m_term_to_id = new HashMap<String, Integer>();
	Map<Integer, String> m_term_id_to_term = new HashMap<Integer, String>();
	
	public ProcessedDb()
	{		
	}
	
	public ProcessedDb(	ArrayList<HashMap<Integer, Float>> tfIdfList, 
						int[] clustr_list, 
						HashMap<Integer, Integer> termid_to_frquenecy, 
						Map<String, Integer> term_to_id, 
						Map<Integer, String> term_id_to_term,
						int[] doc_ids_list)
	{
		m_tfIdfList = tfIdfList;
		m_classes_list = clustr_list;
		
		m_termid_to_frquenecy =  termid_to_frquenecy; 
		m_term_to_id =  term_to_id; 
		m_term_id_to_term = term_id_to_term;
		m_doc_ids_list = doc_ids_list;
	}
	
	public ProcessedDb(float[][] matrix, int[] clustr_list)
	{
		m_TfIdfMatrix = matrix;
		m_classes_list = clustr_list;
	}
	
	public void desriazlie(String file_name)
	{
		ProcessedDb e = null;
	      try
	      {
	         FileInputStream fileIn = new FileInputStream(file_name);
	         ObjectInputStream in = new ObjectInputStream(fileIn);
	         e = (ProcessedDb) in.readObject();
	         in.close();
	         fileIn.close();
	      }catch(IOException i)
	      {
	         i.printStackTrace();
	         return;
	      }catch(ClassNotFoundException c)
	      {
	         c.printStackTrace();
	         return;
	      }
	      
	      m_TfIdfMatrix = e.m_TfIdfMatrix;
	      m_tfIdfList = e.m_tfIdfList;
	      m_classes_list = e.m_classes_list;
	      m_termid_to_frquenecy = e.m_termid_to_frquenecy; 
	      m_term_to_id = e.m_term_to_id; 
	      m_term_id_to_term = e.m_term_id_to_term;
	      m_doc_ids_list = e.m_doc_ids_list;
	}

	public void Serialize(String file_name)
	{
      try
      {
         FileOutputStream fileOut =
         new FileOutputStream(file_name);
         ObjectOutputStream out = new ObjectOutputStream(fileOut);
         out.writeObject(this);
         out.close();
         fileOut.close();
      }
      catch(IOException i)
      {
          i.printStackTrace();
      }	      
	}
	public Integer[] get_all_clusters()
	{
		HashSet<Integer> all_clusters = new HashSet<Integer>();
		for(int i =0; i< m_classes_list.length;++i)
		{
			all_clusters.add(new Integer(m_classes_list[i]));
		}		
		return all_clusters.toArray(new Integer[0]);
	}
}
